<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Update_profile extends MY_Controller {
	
	public function index()
	{
		$this->load->model("customers_model", "model", TRUE);
		$cust_id = $this->session->userdata("cust_id");
		$data['item'] =$this->model->get_record(array("cust_id"=>$cust_id));
		$data['title_options']= array(""=>"Please select", "Mr"=>"Mr", "Mrs"=>"Mrs", "Miss"=>"Miss", "Ms"=>"Ms", "Dr"=>"Dr");
        $data['countries'] = $this->model->get_options("all_countries", "country", "country", "Select your country", "", "country") ;
        $this->template->set("title", "Update Profile");
		$this->template->load("update_profile/update_profile_view", $data);
	}

    function change_password()
    {
       $this->template->set("title", "Change Password");
	   $this->template->load("update_profile/change_password_view");
    }

	function save()
	{
		$this->load->library("form_validation");
        $this->form_validation->set_rules("firstname", "First Name", "trim|required");
        $this->form_validation->set_rules("address", "Address", "trim|required");
		$this->form_validation->set_rules("city", "City", "trim|required");
        $this->form_validation->set_rules("state", "State", "trim|required");
        $this->form_validation->set_rules("country", "Country", "trim|required");
        $this->form_validation->set_rules("phone", "Telephone number", "trim|required");
        $this->form_validation->set_rules("email", "Email", "trim|required|valid_email");

	   

		if($this->form_validation->Run()===FALSE)
		{
			$data['error'] = validation_errors();
		}
		else
		{
	       $user = $this->session->userdata('user');
		   $username = $user['username'];

	       $this->load->model("customers_model", "model", TRUE);
		   $data = $this->model->update_profile($username);
        }

       $this->util->send_json($data);
	}
}

/* End of file update_profile.php */
/* Location: ./application/controllers/update_profile.php */